package cn.northsea.controller;

import cn.northsea.pojo.IncomeInVo;
import cn.northsea.pojo.IncomeOutMaterialVo;
import cn.northsea.pojo.IncomeOutRefundVo;
import cn.northsea.pojo.IncomeVo;
import cn.northsea.service.IncomeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/income")
public class IncomeController {
    @Autowired
    private IncomeService incomeService;

    @RequestMapping("/findAll")
    public String findAll(@RequestParam(required = false,defaultValue = "1")Integer pageNum
            , @RequestParam(required = false,defaultValue = "3")Integer pageSize,
                          Model model, String likename) {
        System.out.println(likename);
        PageHelper.startPage(pageNum, pageSize);
        List<IncomeVo> all = null;
        PageInfo<IncomeVo> pageInfo = null;
        if (StringUtils.isEmpty(likename)) {
            all = incomeService.findAll();
            pageInfo = new PageInfo<>(all);
        } else {
            all = incomeService.like(likename);
            pageInfo = new PageInfo<>(all);
            model.addAttribute("likename", likename);
        }
        model.addAttribute("pageInfo", pageInfo);
        return "incomeList";
    }
    @RequestMapping("/incomeOutMaterialList")
    public String incomeOutMaterialList(@RequestParam(required = false,defaultValue = "1")Integer pageNum
            , @RequestParam(required = false,defaultValue = "5")Integer pageSize,
                                           Model model, String likename1){
        PageHelper.startPage(pageNum,pageSize);
        List<IncomeOutMaterialVo> all = null;
        PageInfo<IncomeOutMaterialVo> pageInfo = null;
        if(StringUtils.isEmpty(likename1))
        {
            all = incomeService.incomeOutMaterialList();
            pageInfo = new PageInfo<>(all);
        }else {
            all=incomeService.like1(likename1);
            pageInfo = new PageInfo<>(all);
            model.addAttribute("likename1",likename1);
        }
        model.addAttribute("pageInfo",pageInfo);
        return "incomeOutMaterialList";
    }
    @RequestMapping("/incomeInList")
    public String incomeInList(@RequestParam(required = false,defaultValue = "1")Integer pageNum
            , @RequestParam(required = false,defaultValue = "5")Integer pageSize,
                                          Model model, String likename2){
        PageHelper.startPage(pageNum,pageSize);
        List<IncomeInVo> all = null;
        PageInfo<IncomeInVo> pageInfo = null;
        if(StringUtils.isEmpty(likename2))
        {
            all = incomeService.incomeInList();
            pageInfo = new PageInfo<>(all);
        }else {
            all=incomeService.like2(likename2);
            pageInfo = new PageInfo<>(all);
            model.addAttribute("likename2",likename2);
        }
        model.addAttribute("pageInfo",pageInfo);
        return "incomeInList";
    }
    @RequestMapping("/incomeOutRefundList")
    public String incomeOutRefundList(@RequestParam(required = false,defaultValue = "1")Integer pageNum
            , @RequestParam(required = false,defaultValue = "5")Integer pageSize,
                                      Model model, String likename3){
        System.out.println(likename3);
        PageHelper.startPage(pageNum,pageSize);
        List<IncomeOutRefundVo> all = null;
        PageInfo<IncomeOutRefundVo> pageInfo = null;
        if(StringUtils.isEmpty(likename3))
        {
            all = incomeService.incomeOutRefundList();
            pageInfo = new PageInfo<>(all);
        }else {
            all=incomeService.like3(likename3);
            pageInfo = new PageInfo<>(all);
            model.addAttribute("likename3",likename3);
        }
        model.addAttribute("pageInfo",pageInfo);
        return "incomeOutRefundList";
    }



}
